using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;

namespace GPUAnimationLib.Runtime
{
    /// <summary>
    /// 动画状态数据
    /// </summary>
    public struct AnimationState
    {
        public float CurrentNormalizedTime;
        public bool CurrentStopped;
        public GPUAnimationData CurrentAnimationData;
        public float PreviousNormalizedTime;
        public bool PreviousStopped;
        public GPUAnimationData PreviousAnimationData;
        public float BlendPreviousToCurrent;
    }

    /// <summary>
    /// 动画状态机数据
    /// </summary>
    public struct AnimatorData
    {
        public int AnimatorId; //动画状态机Id
        public int ProcessState; //0: 关闭 1: 开启
        public float Speed; //动画播放速度
        public int TotalFrames; //总帧数
        public float StartNormalizedTime; //动画播放开始时间（标准化）
        public float TransitionTime; //动画切换过度时间（单位：秒）
        public GPUAnimationData CurrentAnimationData;
        public AnimationState State;

        public bool NeedUpdateToGPU;

        //public float4x4 AnimationState;
        public Matrix4x4 AnimationState;

        public UnsafeList<AttachmentData> AttachmentDatas; //附加物数据集合
        public UnsafeList<Matrix4x4> AnchorTransforms; //附加物计算数据

        public void Dispose()
        {
            if (AttachmentDatas.IsCreated)
                AttachmentDatas.Dispose();
        }
    }

    /// <summary>
    /// 附加物数据
    /// </summary>
    public struct AttachmentData
    {
        public int AttachmentIndex;

        //public Matrix4x4 Transform;
        public Vector3 LocalPosition;
        public Quaternion LocalRotation;
    }
}